package logic

import (
	"context"
	"errors"
	"video/model/mysql"

	"video/videorpc/internal/svc"
	"video/videorpc/videorpc"

	"github.com/zeromicro/go-zero/core/logx"
)

type CollectListLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewCollectListLogic(ctx context.Context, svcCtx *svc.ServiceContext) *CollectListLogic {
	return &CollectListLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

// 收藏列表
func (l *CollectListLogic) CollectList(in *videorpc.CollectListRequest) (*videorpc.CollectListResponse, error) {
	// todo: add your logic here and delete this line

	var user mysql.User

	err := user.FindUserById(mysql.DB, in.UserId)
	if err != nil {
		return nil, errors.New("用户不存在")
	}

	var video mysql.Video

	err = video.FindVideoById(mysql.DB, in.VideoId)
	if err != nil {
		return nil, errors.New("暂无收藏视频，快去收藏喜欢的视频吧～")
	}

	var list []*videorpc.CollectList

	list = mysql.CollectList(mysql.DB, in)

	return &videorpc.CollectListResponse{
		List: list,
	}, nil
}
